<template>
  <div>
    鞋子
    <button @click="xiezi = true">保存</button>
  </div>
</template>
<script>
export default {
  data() {
    return {
      xiezi: false,
    };
  },
  /* 路由进入之前 */
  beforeRouteEnter(to, from, next) {
    console.log("beforeRountEnter");
    next();
  },
  /* 路由要离开时 */
  beforeRouteLeave(to, from, next) {
      console.log("beforeRouteLeave");
    if (this.xiezi) {
      next();
    } else {
      if (confirm("确认要离开吗")) {
        next();
      } else {
        next(false);
      }
    }
  },
  /* 在改变路由时,路由组件重复调用时 */
  beforeRouteUpdate(to, from, next) {
    console.log("beforeRouteUpdate");
    next();
  },
};
</script>
